import java.util.Objects;

/**
 * @Author 12629
 * @Description：
 */
class Person {
    public String id;

    public Person(String id) {
        this.id = id;
    }

    @Override
    public String toString() {
        return "Person{" +
                "id='" + id + '\'' +
                '}';
    }

    /**
     * 一般 自定义的类型 都得重写equals
     * 判断对象是否相同
     * @param obj
     * @return
     */
   /* @Override
    public boolean equals(Object obj) {
        //判断当前的obj参数 是否为空！
        if(obj == null) {
            return false;
        }
        *//**
         * Person person1 = new Person("123");
         *         Person person2 = person1;
         *         System.out.println(person1.equals(person2));
         *//*
        if(this == obj) {
            return true;
        }
        // 不是Person类对象
        if (!(obj instanceof Person)) {
            return false ;
        }
        Person tmp = (Person)obj;
        return this.id.equals(tmp.id);
    }

    *//**
     * 定位你的位置的！
     * @return
     *//*
    @Override
    public int hashCode() {
        return Objects.hash(id);
    }*/

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;

        if (o == null || getClass() != o.getClass()) return false;

        Person person = (Person) o;
        return Objects.equals(id, person.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }

}
class Student {

}
public class Test {

    public static void main(String[] args) {
        Person person1 = new Person("123");
        Person person2 = new Person("123");
        //将来 他们 我也想放到一个位置上
        System.out.println(person1.hashCode());
        System.out.println(person2.hashCode());
    }

    public static void main4(String[] args) {
        Person person1 = new Person("123");
        Student student = new Student();
        System.out.println(person1.equals(student));
    }

    public static void main3(String[] args) {
        Person person1 = new Person("123");
        Person person2 = person1;
        System.out.println(person1.equals(person2));
    }

    public static void main2(String[] args) {
        Person person1 = new Person("123");
        Person person2 = new Person("1232");
        System.out.println(person1 == person2);
        System.out.println(person1.equals(person2));
    }

    public static void func(Object o) {
        //String str = o.toString();
        //System.out.println(str);
        System.out.println(o);
    }

    /*public static void main2(String[] args) {
        func(new Person());
        func(new Student());
    }

    public static void main1(String[] args) {
        Object o = new Person();
        Object o2 = new Student();
    }*/
}
